﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Graph
{
    private List<int>[] childNodes;

    public Graph(List<int>[] childNodes)
    {
        this.childNodes = childNodes;
    }

    public int NodesCount
    {
        get
        {
            return childNodes.Length;
        }
    }

    public List<SortedSet<int>> FindComponents()
    {
        List<SortedSet<int>> subgraphs = new List<SortedSet<int>>();
        bool[] visited = new bool[childNodes.Length];

        for (int i = 0; i < childNodes.Length; i++)
        {
            if (!visited[i])
            {
                subgraphs.Add(new SortedSet<int>());
                FindSubgraphNodes(i, visited, subgraphs[subgraphs.Count - 1]);
            }
        }

        return subgraphs;
    }

    private void FindSubgraphNodes(int node, bool[] visited, SortedSet<int> currentSubgraph)
    {
        // recursive DFS traversal
        visited[node] = true;
        currentSubgraph.Add(node);
        foreach (var childNode in this.childNodes[node])
        {
            if (!visited[childNode])
            {
                FindSubgraphNodes(childNode, visited, currentSubgraph);
            }
        }
    }
}

class Program
{
    static void Main(string[] args)
    {
        Graph graph = new Graph(ReadGraph());

        PrintResult(graph.FindComponents());
    }

    static List<int>[] ReadGraph()
    {
        // Read number of nodes N
        string input = Console.ReadLine();
        int N = int.Parse(input);

        // Read graph as adjacency list
        List<int>[] graph = new List<int>[N];

        for (int i = 0; i < N; i++)
        {
            graph[i] = new List<int>();

            input = Console.ReadLine();
            string[] childs = input.Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            foreach (var child in childs)
            {
                graph[i].Add(int.Parse(child));
            }
        }

        return graph;
    }

    static void PrintResult(List<SortedSet<int>> subgraphs)
    {
        // Print number of subgraphs
        Console.WriteLine(subgraphs.Count);

        // Print sorted elements of each subgraph
        StringBuilder builder = new StringBuilder();
        foreach (var subgraph in subgraphs)
        {
            foreach (var node in subgraph)
            {
                builder.Append(String.Format("{0} ", node));
            }
            builder.Remove(builder.Length - 1, 1);
            Console.WriteLine(builder);
            builder.Clear();
        }
    }
}

